﻿using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Data;
using System.Windows.Controls;
using Thinktecture.UIAnnotations;

namespace Demo
{
    public partial class GenericDemoWindow
    {
        public GenericDemoWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.verticalAlignmentComboBox.ItemsSource = Enum.GetNames(typeof(AdornerVerticalAlignment));
            this.horizontalAlignmentComboBox.ItemsSource = Enum.GetNames(typeof(AdornerHorizontalAlignment));
            this.placementComboBox.ItemsSource = Enum.GetNames(typeof(AdornerPlacement));

            this.verticalAlignmentComboBox.SelectedItem = GenericAdorners.GetVerticalAlignment(this.textBox1).ToString();
            this.horizontalAlignmentComboBox.SelectedItem = GenericAdorners.GetHorizontalAlignment(this.textBox1).ToString();
            this.placementComboBox.SelectedItem = GenericAdorners.GetPlacement(this.textBox1).ToString();
            this.textBox1.Focus();
        }

        private void verticalAlignmentComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            AdornerVerticalAlignment value;
            if (Enum.TryParse<AdornerVerticalAlignment>(e.AddedItems[0].ToString(), out value))
                GenericAdorners.SetVerticalAlignment(this.textBox1, value);
            this.textBox1.Focus();
        }

        private void horizontalAlignmentComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            AdornerHorizontalAlignment value;
            if (Enum.TryParse<AdornerHorizontalAlignment>(e.AddedItems[0].ToString(), out value))
                GenericAdorners.SetHorizontalAlignment(this.textBox1, value);
            this.textBox1.Focus();
        }

        private void placementComboBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            AdornerPlacement value;
            if (Enum.TryParse<AdornerPlacement>(e.AddedItems[0].ToString(), out value))
                GenericAdorners.SetPlacement(this.textBox1, value);
            this.textBox1.Focus();
        }

        private void closeButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
   }
}